package com.voja.mrvica2.adapter;

import java.util.ArrayList;

import com.voja.mrvica2.Entry;
import com.voja.mrvica2.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MenuAdapter extends ArrayAdapter<Entry> {
    
    public static final String TAG = "item-%d";

    private ArrayList<Entry> categories;
    private Context context;
    private int resourceId;
    
    public MenuAdapter(Context context, int resourceId, ArrayList<Entry> categories) {
        super(context, resourceId);
        
        this.context    = context;
        this.resourceId = resourceId;
        this.categories = categories;
    }
    
    @Override
    public Entry getItem(int position) {
        return categories.get(position);
    }
    
    @Override
    public int getCount() {
        return categories.size();
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        
        View v = convertView;
        if (v == null) {
            LayoutInflater inflater = LayoutInflater.from(context);
            v = inflater.inflate(resourceId, null);
        }
        
        Entry entry = categories.get(position);
        if (entry != null) {
            TextView title = (TextView)v.findViewById(R.id.itemTitle);
            title.setText(entry.getTitle());
            
            ProgressBar throb = (ProgressBar)v.findViewById(R.id.throbber);
            throb.setVisibility(View.GONE);
        }
        return v;
    }

}
